package bdd.sql.server.bean;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Bean ServerSite.
 * @author Guillaume Pocas & Jean-Fraçois Augé
 */
@Entity
@Table(name = "kraken_server_site")
public class ServerSite {

	@Id
	@GeneratedValue
	@Column(name = "siteserv_id")
	private int siteserv_id;
	
	@Column(name = "siteserv_name", unique = true, nullable = false, updatable = false)
	private String siteserv_name;
	
	@Column(name = "siteserv_ip_adress", unique = true, nullable = false, updatable = false)
	private String siteserv_ip;
	
	@Column(name = "cluster_name", nullable = false)
	private String siteserv_cluster;
	
	@ManyToOne(cascade = {CascadeType.ALL})
    @JoinColumn(name = "id_server_central")
	private ServerCentral serveur_central;
	
	@OneToMany(mappedBy="serveur_site")
    private Set<Camera> cameras;
	
	@ManyToOne(cascade = {CascadeType.ALL})
    @JoinColumn(name = "id_encryption")
	private Encryption encryption;
	
	@Column(name = "site_key", unique = true, nullable = false)
	private String siteserv_key;
	
	@OneToOne(mappedBy = "site")
	private Keystore keystore;
	
	@OneToOne(mappedBy = "site")
	private ServerStorage serverStorage;

	@ManyToOne(cascade = {CascadeType.ALL})
    @JoinColumn(name = "id_conf")
	private Configuration site_conf;
	
	/**
	 * Constructeur vide.
	 */
	public ServerSite() {}
 
	/**
	 * Constructeur.
	 * @param name nom du site
	 * @param ip adresse du site
	 */
	public ServerSite(String name, String ip, String cluster, String key) {
		this.siteserv_name = name;
		this.siteserv_ip = ip;
		this.siteserv_cluster = cluster;
		this.siteserv_key = key;
		this.cameras = new HashSet<Camera>();
	}
	
	public ServerSite(String name, String ip, String cluster, String key, ServerCentral gs) {
		this.siteserv_name = name;
		this.siteserv_ip = ip;
		this.siteserv_cluster = cluster;
		this.siteserv_key = key;
		this.serveur_central = gs;
		this.cameras = new HashSet<Camera>();
	}
	
	public ServerSite(String name, String ip, String cluster, String key, Encryption encrypt, ServerCentral gs) {
		this.siteserv_name = name;
		this.siteserv_ip = ip;
		this.siteserv_cluster = cluster;
		this.siteserv_key = key;
		this.encryption = encrypt;
		this.serveur_central = gs;
		this.cameras = new HashSet<Camera>();
	}
	
	public int getSiteserv_id() { return siteserv_id;	}
	public void setSiteserv_id(int siteserv_id) { this.siteserv_id = siteserv_id;	}

	public String getSiteserv_name() { return siteserv_name;	}
	public void setSiteserv_name(String siteserv_name) { this.siteserv_name = siteserv_name;	}

	public String getSiteserv_ip() { return siteserv_ip;	}
	public void setSiteserv_ip(String siteserv_ip) { this.siteserv_ip = siteserv_ip;	}

	public String getSiteserv_cluster() { return siteserv_cluster;	}
	public void setSiteserv_cluster(String siteserv_cluster) { this.siteserv_cluster = siteserv_cluster;	}

	public ServerCentral getGlobalServer() { return serveur_central;	}
	public void setGlobalServer(ServerCentral serverCentral) { this.serveur_central = serverCentral;	}

	public Set<Camera> getCameras() { return cameras;	}
	public void setCameras(Set<Camera> cameras) { this.cameras = cameras;	}
	public void addCamera(Camera camera){	this.cameras.add(camera);	}
	public void delCamera(Camera camera){	this.cameras.remove(camera);	}

	public Encryption getEncryption() { return encryption;	}
	public void setEncryption(Encryption encryption) { this.encryption = encryption;	}

	public String getSiteserv_key() { return siteserv_key;	}
	public void setSiteserv_key(String siteserv_key) { this.siteserv_key = siteserv_key;	}
	
	public Keystore getKeystore() {	return keystore;	}
	public void setKeystore(Keystore keystore) {	this.keystore = keystore;	}
	
	public ServerCentral getServeur_global() {	return serveur_central;	}
	public void setServeur_global(ServerCentral serveur_global) {	this.serveur_central = serveur_global;	}

	public ServerStorage getServerStorage() {	return serverStorage;	}
	public void setServerStorage(ServerStorage serverStorage) {	this.serverStorage = serverStorage;	}
	
	public Configuration getConf() { return site_conf; }
	public void setConf(Configuration site_conf) { this.site_conf = site_conf; }

	@Override
	public String toString(){ return this.siteserv_name; }

}
